package com.wwwarehouse.taskcenter.fragment.job_point.step6;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.adapter.job_point.JobPointChooseObject6Adapter;
import com.wwwarehouse.taskcenter.bean.job_point.AddJobPointStep6ResponseBean;
import com.wwwarehouse.taskcenter.constant.TaskCenterConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * @创建者 chenchao.
 * @创建时间 2017/10/25 18:57
 * @描述 ${TODO}
 */

public class ChooseConnectObjectDetailFragment6 extends BaseFragment {

    private View mView;
    private RecyclerView mTaskPointRecycleview;
    private StateLayout mSlLayout;
    private static final int REQUEST_1 = 100002;
    private int page;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_choose_object_detail_6, container, false);
        initView(mView);
        return mView;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ChooseConnectObjectDetailFragment6) {
            mActivity.setTitle(getString(R.string.taskpoint_choose_relatething));
        }
    }

    @Override
    public void requestDatas() {

    }

    /**
     *  查询四权 分页接口，一个页面请求一次的.
     */
    public void requestDataMy() {

        String searchKey = getArguments().getString("searchKey");
        String mSort = getArguments().getString("mSort");


        Map<String, Object> map = new HashMap<>();
        map.put("name","" + searchKey);
        Map<String , Object> queryMap = new HashMap<>();
        queryMap.put("page",page);
        queryMap.put("size",10);
        queryMap.put("sort","" + mSort);

        map.put("query",queryMap);

        NoHttpUtils.httpPost(TaskCenterConstant.URL_ADD_JOBPOINT_STEP6_SEARCH_WAY,map,myResponse,REQUEST_1);
    }

    NoHttpUtils.OnResponseListener myResponse = new NoHttpUtils.OnResponseListener() {
        @Override
        public void onSucceed(CommonClass commonClass, int y) {
            switch (y){
                case REQUEST_1:
                    if("0".equals(commonClass.getCode())){
                        AddJobPointStep6ResponseBean bean = JSON.parseObject(commonClass.getData().toString(), AddJobPointStep6ResponseBean.class);
                        mTaskPointRecycleview.setAdapter(new JobPointChooseObject6Adapter(bean.getList(),mActivity));
                    }else{
                        toast("" + commonClass.getMsg());
                    }

                    break;
            }
        }
        @Override
        public void onFailed(String s, int i) {
        }
        @Override
        public void onFinish(int i) {

        }
    };

    private void initView(View mView) {
        mTaskPointRecycleview = (RecyclerView) mView.findViewById(R.id.task_point_recycleview);
        mSlLayout = (StateLayout) mView.findViewById(R.id.sl_layout);

        mTaskPointRecycleview.setLayoutManager(new LinearLayoutManager(mActivity));

        page = getArguments().getInt("page");
        requestDataMy();//oncreateanimation 返回了null之后，会造成没有办法调动画结束的请求，所以，自己调用。
    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }
}
